package com.demo.jgit;

import java.io.File;
import java.io.IOException;

import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.Status;
import org.eclipse.jgit.lib.BranchTrackingStatus;
import org.eclipse.jgit.lib.Repository;
/**
 * git status 
 * @author Administrator
 *
 */
public class StatusDemo {

	public static void main(String[] args) throws Exception {
		File gitpath=new File("I:\\gitWorkspace\\demo\\.git");
		Git git=Git.open(gitpath);
		Repository repo=git.getRepository();
		String branch=repo.getBranch();
		BranchTrackingStatus branchStatus=BranchTrackingStatus.of(repo, branch);
		if(branchStatus==null) {
			System.out.println("远程没有该分支");
		}
		System.out.println(branchStatus.getAheadCount());//有多少个没推送
		System.out.println(branchStatus.getBehindCount());//有多少个没拉取
		Status status=git.status().call();
		//Your branch is ahead of 'origin/master' by 2 commits.

		
		
			//指有没有commit的文件
		  boolean isDirty=!status.isClean();
		  System.out.format("Repo is in dirty state = [%s] ",isDirty);
		  
		  
	}

}
